package com.sc.nft.dao;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.merchantPledgeTask.AdminExaminePageVO;
import com.sc.nft.entity.vo.merchantPledgeTask.MerchantPledgeTaskPageVO;
import com.sc.nft.enums.MerchantPledgeTaskExamineStatusEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MerchantPledgeTaskConf;
import com.sc.nft.mapper.MerchantPledgeTaskConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 商户质押任务配置主表(sc_merchant_pledge_task_conf)数据DAO
 *
 * @author Sun
 * @since 2023-08-24 16:16:49
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class MerchantPledgeTaskConfDao extends ServiceImpl<MerchantPledgeTaskConfMapper, MerchantPledgeTaskConf> {

    public Page<AdminExaminePageVO> getAdminExaminePage(Page page, String daoName, MerchantPledgeTaskExamineStatusEnum examineStatus) {
        return baseMapper.getAdminExaminePage(page, daoName, ObjectUtil.isNull(examineStatus) ? null : examineStatus.getCode());
    }

    public boolean updateExamineStatusById(Long id, MerchantPledgeTaskExamineStatusEnum examineStatus,String reason) {
        LambdaUpdateWrapper<MerchantPledgeTaskConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantPledgeTaskConf::getId, id);
        wrapper.set(MerchantPledgeTaskConf::getExamineStatus, examineStatus);
        wrapper.set(ObjectUtil.isNotNull(reason),MerchantPledgeTaskConf::getReason, reason);
        return update(new MerchantPledgeTaskConf(),wrapper);
    }

    public Page<MerchantPledgeTaskPageVO> getTaskPage(Long daoId,Integer pageNo, Integer pageSize) {
        return baseMapper.getTaskPage(new Page<>(pageNo, pageSize),daoId);
    }

    public boolean updatePledgeTaskInfo(MerchantPledgeTaskConf merchantPledgeTaskConf) {
        LambdaUpdateWrapper<MerchantPledgeTaskConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(MerchantPledgeTaskConf::getId,merchantPledgeTaskConf.getId());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getPledgeName()),MerchantPledgeTaskConf::getPledgeName,merchantPledgeTaskConf.getPledgeName());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getActivityCover()),MerchantPledgeTaskConf::getActivityCover,merchantPledgeTaskConf.getActivityCover());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getRuleSpecification()),MerchantPledgeTaskConf::getRuleSpecification,merchantPledgeTaskConf.getRuleSpecification());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getBeginTime()),MerchantPledgeTaskConf::getBeginTime,merchantPledgeTaskConf.getBeginTime());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getEndTime()),MerchantPledgeTaskConf::getEndTime,merchantPledgeTaskConf.getEndTime());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getUpperLimit()),MerchantPledgeTaskConf::getUpperLimit,merchantPledgeTaskConf.getUpperLimit());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getUserCount()),MerchantPledgeTaskConf::getUserCount,merchantPledgeTaskConf.getUserCount());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getActivityDetailsImage()),MerchantPledgeTaskConf::getActivityDetailsImage,merchantPledgeTaskConf.getActivityDetailsImage());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getIsShow()),MerchantPledgeTaskConf::getIsShow,merchantPledgeTaskConf.getIsShow());
        wrapper.set(ObjectUtil.isNotEmpty(merchantPledgeTaskConf.getShowLocationDaoId()),MerchantPledgeTaskConf::getShowLocationDaoId,merchantPledgeTaskConf.getShowLocationDaoId());
        return update(new MerchantPledgeTaskConf(),wrapper);
    }
}